package com.ai.demo;

import io.modelcontextprotocol.client.McpSyncClient;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.List;
import java.util.Scanner;

@SpringBootApplication
public class AiDemoApplication {



    public static void main(String[] args) {
        SpringApplication.run(AiDemoApplication.class, args);
    }

    //@Bean
    //public CommandLineRunner chatbot(@Qualifier("deepSeekChatModel") ChatModel chatModel, List<McpSyncClient> mcpSyncClients) {
    //    return args -> {
    //        var chatClient =  ChatClient.builder(chatModel)
    //                //.defaultSystem("You are useful assistant and can perform web searches Brave's search API to reply to your questions.")
    //                .defaultToolCallbacks(new SyncMcpToolCallbackProvider(mcpSyncClients))
    //                .defaultAdvisors(MessageChatMemoryAdvisor.builder(MessageWindowChatMemory.builder().build()).build())
    //                .build();
    //
    //        // Start the chat loop
    //        System.out.println("\nI am your AI assistant.\n");
    //        try (Scanner scanner = new Scanner(System.in)) {
    //            while (true) {
    //                System.out.print("\nUSER: ");
    //                System.out.println("\nASSISTANT: " +
    //                        chatClient.prompt(scanner.nextLine()) // Get the user input
    //                                .call()
    //                                .content());
    //            }
    //        }
    //    };
    //
    //}

    /**
     * 定义一个CommandLineRunner类型的Bean，用于在程序启动时执行
     *
     * @param builder ChatClient.Builder对象，用于构建ChatClient对象
     * @return CommandLineRunner对象
     */
    //@Bean
    //public CommandLineRunner runner(ChatClient.Builder builder) {
    //    // 返回一个Lambda表达式，表示在程序启动时执行的代码
    //    return args -> {
    //        // 使用builder构建一个ChatClient对象
    //        ChatClient chatClient = builder.build();
    //        // 调用ChatClient对象的prompt方法，传入参数"你是谁？"
    //        String response = chatClient.prompt("你是谁？").call().content();
    //        System.out.println(response);
    //    };
    //}
}
